package com.crazy.proxy;

import cn.hutool.aop.aspects.Aspect;
import cn.hutool.core.date.TimeInterval;

import java.lang.reflect.Method;

/**
 * @author panyonghui
 * @describe 代理切面实现
 * @date 2023/1/5 17:41
 */
public class MyAspect implements Aspect {
    private final TimeInterval interval = new TimeInterval();
    @Override
    public boolean before(Object o, Method method, Object[] objects) {
        System.out.println(String.format("className:[%s],methodName:[%s]", o.getClass().getName(),method.getName()));
        return true;
    }

    @Override
    public boolean after(Object o, Method method, Object[] objects, Object o1) {
        System.out.println(String.format("耗时:[%s],返回结果:%s", this.interval.intervalMs(), o1));
        return true;
    }

    @Override
    public boolean afterException(Object o, Method method, Object[] objects, Throwable throwable) {
        return false;
    }
}
